﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Runtime.InteropServices;
using ICSharpCode.SharpZipLib.Zip;

namespace Player
{
    public class CaptureContract
    {
        public const string MODULE_GUID = "{2738572A-276C-42dc-8AB6-B77CB449D6F9}";
        public enum CaptureOpcode : byte
        {
            StartSession = 0x01,
            Rectangle,
            WindowEvent,
            ColorMap,
            EndSession,
            FlushFrameset,
            Reply = 0x80,
            StartSessionReply = StartSession | Reply,
            RectangleReply = Rectangle | Reply,
            WindowEventReply = WindowEvent | Reply,
            ColorMapReply = ColorMap | Reply,
            EndSessionReply = EndSession | Reply,
            FlushFramesetReply = FlushFrameset | Reply
        };
        public enum StoredEncoding : int
        {
            Compression = 0x80,     // Is the data compressed
            Raw = 0x00,             // Raw encoding
            CopyRect = 0x01,        // CopyRect (never compressed)
            RRE = 0x02,             // RRE rectangle
            CompressedRaw = Compression | Raw,  // Compressed Raw data
            Low = 0x40,             // 8 bpp
            Medium = 0x20,          // 16 bpp
            High = 0x10,             // 32 bpp
            DesktopResize = -223,   // Desktop resize rectangle (no data)
        };
        public enum PixelFormat : byte
        {
            Mapped1Byte = 1, // palletized
            Raw2Byte555,
            Raw2Byte565,
            Raw4Byte888,
        };
        static public int GetBytesPerPixel(PixelFormat format)
        {
            int bpp = 0;
            switch (format)
            {
                case PixelFormat.Mapped1Byte:
                    bpp = 1;
                    break;
                case PixelFormat.Raw2Byte555:
                case PixelFormat.Raw2Byte565:
                    bpp = 2;
                    break;
                case PixelFormat.Raw4Byte888:
                    bpp = 4;
                    break;
            }

            return bpp;
        }
    }

    public abstract class RfbRect
    {
        public Point Location { get; set; }
        public Size Size { get; set; }
        public CaptureContract.StoredEncoding StoreEncoding { get; set; }
    }

    public class RfbRectScreenResize : RfbRect
    {
    }

    public class RfbRectCopyRect : RfbRect
    {
        public Point Source { get; set; }
    }

    public class RfbRectRaw : RfbRect
    {
        public byte[] Pixels { get; set; }
    }

    public class EventItem
    {
        public DateTime DateTime { get; set; }
        public long TimeStamp { get; set; }
    }
}